package com.example.controller;

import com.example.domain.Password;
import com.example.domain.Result;
import com.example.domain.Account;
import com.example.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserServiceImpl userService;

    @RequestMapping("/picture/{email}")
    public Result updatePicture(@RequestParam("file") MultipartFile file,@PathVariable String email){
//        System.out.println(file);
        return userService.updatePicture(file,email);
    }
    @DeleteMapping("{email}/{image}")
    public Result cancelPicture(Account account){
        return userService.cancelPicture(account);
    }
    @PutMapping("/{email}/{image}")
    @ResponseBody
    public Result savePicture( Account account){
//        System.out.println(file);
        return userService.savePicture(account);
    }
    @GetMapping("/get-user")
    @ResponseBody
    public Result getUser(HttpServletRequest request){
        return userService.getUser(request);
    }
    @DeleteMapping("/logout")
    @ResponseBody
    public Result logout(HttpServletRequest request){
        return userService.logout(request);
    }
    @PostMapping("/updatePassword/{email}")
    public Result updatePassword(@PathVariable String email, @RequestBody Password password){
        return userService.updatePassword(email, password);
    }
}
